import time

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction

cap = {}
cap['platformName'] = "Android"
cap['platformVersion'] = "7.1.2"
cap["appPackage"] = "com.lingyue.zebraloan"            #APP包名：可以通过 adb shell pm list packages -3 或者是将当前应用运行，使用：adb shell dumpsys activity activities
cap["appActivity"] = "com.lingyue.banana.activities.BananaLaunchActivity"          # Activity事件：将当前应用运行，使用：adb shell dumpsys activity activities获取
cap['deviceName'] = "x1q"

# 初始化driver
driver = webdriver.Remote("http://localhost:4723/wd/hub",cap)

# 设置隐式等待
driver.implicitly_wait(15)

# 点击同意按钮
driver.find_element(MobileBy.ID,"com.lingyue.zebraloan:id/tv_confirm").click()

# 使用tap点击 ：立即借款
time.sleep(5)
TouchAction(driver).tap(x = 512,y = 499).perform() # tap操作是瞬发的，所以要加一个强制等待

# 使用class name点击隐私协议
# driver.find_element(MobileBy.CLASS_NAME,"android.widget.CheckBox").click()

#使用tap点击：隐私协议
time.sleep(2)
TouchAction(driver).tap(x = 653,y = 861).perform()

# 滑动隐私协议
time.sleep(2)
TouchAction(driver).press(x = 355,y = 1399).move_to(x = 339,y = 363).release().perform()

time.sleep(2)
TouchAction(driver).press(x = 411,y = 1535 ).move_to(x = 345,y = 154).release().perform()

"""
press(x = 355,y = 1399)：从x355~y1399开始滑动
move_to(x = 339,y = 363)：滑动到x339~y363结束
release()：松开手指
perform()：执行这个操作
"""



